package juc.countdownlatch;

import java.util.concurrent.CountDownLatch;

/**
 * 员工线程
 */
public class EmployeeThread extends Thread {

	private String employeeName; // 员工姓名
	
	private CountDownLatch countDownLatch;
	
	EmployeeThread(String employeeName, CountDownLatch countDownLatch) {
		this.employeeName = employeeName;
		this.countDownLatch = countDownLatch;
	}
	
	@Override
	public void run() {
		System.out.println(System.currentTimeMillis() + "\t 员工：" + employeeName + " 到达会议室");
		
		try {
			countDownLatch.countDown(); // 到达一个员工，计数器就-1
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// 员工在正式开会之前，是可以继续后续动作的，不会被阻塞
		String action = "";
		if(employeeName.equals("zhangsan")) {
			action = "玩手机";
		} else if(employeeName.equals("lisi")) {
			action = "准备发言稿";
		} else {
			action = "发呆中...";
		}
		System.out.println(System.currentTimeMillis() + "\t 员工：" + employeeName + " 开会之前在 " + action);
	}
}
